import { Controller, Get, Post, Body, Patch, Param, Delete,Query,Req,UseGuards} from '@nestjs/common';
import { MenuService } from './menu.service';
import { CreateMenuDto,UpdateMenuDto,ListMenuDto } from './dto';
import { LoginGuard } from '../../../login/login.guard';


@Controller('system/menu')
export class MenuController {
  constructor(private readonly menuService: MenuService) {}

  
  @UseGuards(LoginGuard)
  @Post('/add')
  create(@Body() createMenuDto: CreateMenuDto) {
    return this.menuService.create(createMenuDto);
  }

  @UseGuards(LoginGuard)
  @Get('/findAll')
  findAll(@Query() query: ListMenuDto, @Req() req) {
    if(query&&query.pageNum){
      return this.menuService.findPage(query,req);
    }else{
      return this.menuService.find();
    }
  }

  @UseGuards(LoginGuard)
  @Get('/findOne')
  findOne(@Param('id') id: string) {
    return this.menuService.findOne(id);
  }

  @UseGuards(LoginGuard)
  @Get('/findTree')
  findTree() {
    return  this.menuService.findTree();
  }

  @UseGuards(LoginGuard)
  @Post('/update')
  update(@Body() UpdateMenuDto: UpdateMenuDto) {
    return this.menuService.update(UpdateMenuDto);
  }

  // @Post('/remove')
  // remove(@Body() ids: string[]) {
  //   return this.menuService.remove(ids);
  // }
}
